//
//  BaseViewController.swift
//  WBTest
//
//  Created by 张海峰 on 2017/7/21.
//  Copyright © 2017年 张海峰. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {
    //MARK:-   懒加载属性
    lazy var visitorView :VisitorView = VisitorView.visitorView()
    //MARK:-   定义变量
    var isLogin :Bool = UserInfoViewModel().isLogin
    //MARK:-   系统回调函数
    override func loadView() {
        print(UserInfoViewModel().isLogin)
        print(UserInfoViewModel().user?.name ?? "")
       isLogin ? super.loadView() : setupVisitorView()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupNavigationItems()
    }
}
extension BaseViewController{
    func setupVisitorView(){
     view = visitorView
        visitorView.zhuCeBtn.addTarget(self, action: #selector(zhuceBtnClick), for: .touchUpInside)
        visitorView.dengLuBtn.addTarget(self, action: #selector(dengLuBtnClick), for: .touchUpInside)
    }
    //2. 设置访导航栏的左右Item
    func setupNavigationItems()
    {
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "注册", style: .plain, target: self, action: #selector(zhuceBtnClick))
//        navigationItem.leftBarButtonItem?.tintColor = UIColor.orange
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "登录", style: .plain, target: self, action: #selector(dengLuBtnClick))
       // navigationItem.rightBarButtonItem?.tintColor = UIColor.red
    }
}
//MARK:- 监听点击事件
extension BaseViewController
{
    func zhuceBtnClick() {
        print("注册")
    }
    func dengLuBtnClick() {
        print("登录")
        let OAuthVc = OAuthViewController()
        let OAuthNav = UINavigationController.init(rootViewController: OAuthVc)
        present(OAuthNav, animated: true, completion: nil)
    }
}
